//
//  MMainLayer.m
//  Coffee
//
//  Created by sabhanayagam b on 4/27/11.
//  Copyright 2011 Cognizant. All rights reserved.
//

#import "MMainLayer.h"
#import "GameManager.h"

@implementation MMainLayer
// on "init" you need to initialize your instance
-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if( (self=[super init] )) {
		
		// ask director the the window size
		CGSize size = [[CCDirector sharedDirector] winSize];
		
		//Title
		CCLabelTTF *title = [CCLabelTTF labelWithString:@"Main Menu" fontName:@"Marker Felt" fontSize:32];
		[title setColor:ccBLACK];
		// position the label on the center of the screen
		title.position =  ccp( size.width * .5 , size.height - OFFSET  );
		// add the label as a child to this Layer
		[self addChild: title];
		
		//NSArray  * menuItemLabel = [NSArray arrayWithObjects:@"Play",@"Levels",@"Settings",@"About Us",nil];
		
		//Play
		CCLabelTTF *playLabel = [CCLabelTTF labelWithString:@"Play" fontName:@"Marker Felt" fontSize:24];
		CCMenuItemLabel *play = [CCMenuItemLabel itemWithLabel:playLabel target:self selector:@selector(playHandler:)];

		//Levels
		CCLabelTTF *levelLabel = [CCLabelTTF labelWithString:@"Levels" fontName:@"Marker Felt" fontSize:24];
		CCMenuItemLabel *level = [CCMenuItemLabel itemWithLabel:levelLabel target:self selector:@selector(levelHandler:)];
		
		//Settings
		CCLabelTTF *settingsLabel = [CCLabelTTF labelWithString:@"Settings" fontName:@"Marker Felt" fontSize:24];
		CCMenuItemLabel *settings = [CCMenuItemLabel itemWithLabel:settingsLabel target:self selector:@selector(settingsHandler:)];

		
		//Main Container
		CCMenu *menu = [CCMenu menuWithItems: play, level,settings, nil];
		[menu alignItemsVertically];
		[menu setColor:ccBLACK];
		[self addChild: menu];
		
		//Positioning
		// elastic effect
		/*CGSize s = [[CCDirector sharedDirector] winSize];
		int i=0;
		for( CCNode *child in [menu children] ) {
			CGPoint dstPoint = child.position;
			int offset = s.width/2 + 50;
			if( i % 2 == 0)
				offset = -offset;
			child.position = ccp( dstPoint.x + offset, dstPoint.y);
			[child runAction: 
			 [CCEaseElasticOut actionWithAction:
			  [CCMoveBy actionWithDuration:2 position:ccp(dstPoint.x - offset,0)]
										 period: 0.35f]
			 ];
			i++;
		}*/
		
		
	}
	return self;
}
//Button Click handlers
-(void) playHandler: (id) sender
{
	[[GameManager sharedGameInfo] switchScene:TargetGameScene];
}
-(void) levelHandler: (id) sender
{
}
-(void) settingsHandler: (id) sender
{
	[(CCMultiplexLayer*)parent_ switchTo:1];
}

// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
	// in case you have something to dealloc, do it in this method
	// in this particular example nothing needs to be released.
	// cocos2d will automatically release all the children (Label)
	
	// don't forget to call "super dealloc"
	[super dealloc];
}
@end
